from django.contrib.auth.models import User, AbstractUser
from django.db import models
from ckeditor_uploader.fields import RichTextUploadingField


class Type(models.Model):
    id = models.AutoField(verbose_name='ID', primary_key=True)
    type = models.CharField(default='', verbose_name='问题类型', max_length=20)

    def __str__(self):
        return self.type

    class Meta:
        verbose_name = '问题类型'


class Article(models.Model):
    # 唯一id
    article_id = models.AutoField(verbose_name='ID', primary_key=True)
    # 标题
    title = models.CharField(verbose_name='标题', max_length=30)
    # 正文
    content = RichTextUploadingField(verbose_name='主要内容')
    # 发布时间
    publish_date = models.DateTimeField(verbose_name='发布时间', auto_now=True)
    # 发布人
    author = models.ForeignKey(User, verbose_name='作者', on_delete=models.DO_NOTHING, null=True)
    type = models.ForeignKey(Type, on_delete=models.DO_NOTHING, null=True)

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = '问题'
